package com.duolaibei.business.view.goods.mode;

import com.duolaibei.business.view.App;
import com.duolaibei.business.view.goods.greendao.DaoSession;
import com.duolaibei.business.view.goods.greendao.TypesBeanDao;

import java.util.ArrayList;
import java.util.List;

public class TypesBeanManager {
    private static TypesBeanManager instance;
    TypesBeanDao typesBeanDaoDao;
    DaoSession daoSession;

    private TypesBeanManager() {
        typesBeanDaoDao = App.getApp().getDaoSession().getTypesBeanDao();
        daoSession = App.getApp().getDaoSession();
    }

    public static TypesBeanManager getInstance() {
        if (instance == null) {
            synchronized (TypesBeanManager.class) {
                if (instance == null) {
                    instance = new TypesBeanManager();
                }
            }
        }
        return instance;
    }

    //增加
    public void addType(TypesBean testBean) {
        typesBeanDaoDao.insert(testBean);
    }

    //删除
    public void deleteTypes(TypesBean testBean) {
        typesBeanDaoDao.delete(testBean);
    }

    //修改
    public void updateTypes(TypesBean testBean) {
        typesBeanDaoDao.update(testBean);
    }

    //条件查询
    public List selectAllTypes() {
        typesBeanDaoDao.detachAll();//清除缓存
        List list1 = typesBeanDaoDao.queryBuilder().build().list();
        return list1 == null ? new ArrayList() : list1;
    }

    //删除表中内容
    public void deleteAllTypes() {
        typesBeanDaoDao.deleteAll();
    }
}
